<template>
  <div class="container">
    <el-dialog
      :title="titleInfo"
      :visible="showDialog"
      @close="closeDialog"
      style="height:100%"
    >
      <!-- 表单 -->
      <el-form ref="formRef" label-width="120px" :model="form" :rules="rules" style="height:100%">
        <el-form-item label="新闻标题" prop="title" >
          <el-input style="width: 50%" placeholder="请输入文章标签" v-model="form.title"/>
        </el-form-item>
        <el-form-item label="文章内容" prop="articleBody" >
          <QuillEditor v-model="form.articleBody"></QuillEditor>
        </el-form-item>
        <el-form-item label="视频地址" prop="videoURL">
          <el-input style="width: 50%" placeholder="请输入视频地址" v-model="form.videoURL" />
        </el-form-item>
      </el-form>
      <!-- footer插槽 -->
      <template v-slot:footer>
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="Submit">确定</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { add, update, detail } from '@/api/hmmm/articles'
import QuillEditor from './quill-editor.vue'
export default {
  components: {
    QuillEditor
  },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    titleInfo: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      form: {
        id: '',
        articleBody: '',
        title: '',
        videoURL: ''
      },
      rules: {
        title: [
          { required: true, message: '文章标题不能为空', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '文章内容不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 获取文章详情回显
    async Editshow (row) {
      // console.log(11)
      const { data } = await detail(row)
      this.form = data
    },
    // 关闭对话框
    closeDialog () {
      this.$emit('update:showDialog', false)
      this.$refs.formRef.resetFields()
    },
    // 添加员工
    Submit () {
      // 1. 预校验
      this.$refs.formRef.validate(async boo => {
        if (!boo) return
        if (!this.form.id) {
          // 2. 准备接口  携带参数发送请求
          await add(this.form)
        } else {
          await update(this.form)
        }
        // 关闭对话框 重置表单
        this.closeDialog()
        // 通知父组件重新获取一下
        this.$emit('reload')
      })
    }

  }
}
</script>

<style>
</style>
